package ItemTest;

import static org.junit.Assert.*;
import item.itsUsers;
import item.itsUsersMementoCaretaker;

import org.junit.Test;

public class itsUsersTest {

	@Test
	public void test() {
		itsUsers aUser = new itsUsers();
		assertNotNull(aUser);
	}
	
	@Test
	public void setDatosUserTest(){
		itsUsers aUser = new itsUsers();
		aUser.setDatosUser( "oscar", "olcb", "123");
		assertEquals(aUser.getUsername(),"oscar");
	}

	@Test
	public void simpleMementoTest(){
		itsUsersMementoCaretaker undo = new itsUsersMementoCaretaker();
		itsUsers user = new itsUsers();
		user.setDatosUser("pepe", "pepe@pepe.org", "123");
		//seteo el id a manopla, debe ser que el unico que lo cambia es JPA con la persistencia => ver: itsUsersJPATest.java
		user.setId(100);
		undo.guardarEstado(user.crearMemento());
		//cambio datos:
		user.setDatosUser("luis", "luis@pepe.org", "luis");		
		//deberia poder hacer UNDO:
		undo.obtenerEstado(user);				
		assertEquals(user.getUsername(),"pepe");
	}
	
	@Test
	public void multipleMementoTest(){
		itsUsersMementoCaretaker undo = new itsUsersMementoCaretaker();
		
		itsUsers user1 = new itsUsers();
		user1.setDatosUser("pepe1", "pepe@pepe.org", "123");
		user1.setId(100);
		undo.guardarEstado(user1.crearMemento());
		
		
		itsUsers user2 = new itsUsers();
		user2.setDatosUser("luis1", "luis@pepe.org", "luis");
		user2.setId(101);
		undo.guardarEstado(user2.crearMemento());
		
		
		itsUsers user3 = new itsUsers();
		user3.setId(102);
		user3.setDatosUser("martin1", "martin@pepe.org", "qqqqq");
		undo.guardarEstado(user3.crearMemento());
		
		//cambio datos USER1
		user1.setDatosUser("pepe2", "pepe@pepe.org", "123");		
		undo.guardarEstado(user1.crearMemento());
		user1.setDatosUser("pepe3", "pepe@pepe.org", "123");		
		undo.guardarEstado(user1.crearMemento());
		//cambio datos USER3
		user3.setDatosUser("martin2", "martin@pepe.org", "qqqqq");
		undo.guardarEstado(user3.crearMemento());
		user3.setDatosUser("martin3", "martin@pepe.org", "qqqqq");
		undo.guardarEstado(user3.crearMemento());
		user3.setDatosUser("martin4", "martin@pepe.org", "qqqqq");
		undo.guardarEstado(user3.crearMemento());		
		
		//deberia poder hacer UNDO:
		undo.obtenerEstado(user1);//=ultimo undo => pepe3
		undo.obtenerEstado(user3,1);//undo nro 1 => martin2
		System.out.println("user1="+user1.getUsername());
		System.out.println("user3="+user3.getUsername());
		assertTrue((user1.getUsername().equals("pepe3") ) && (user3.getUsername().equals("martin2")));
	}	
}
